package com.hopu.erp.controller;

import com.hopu.erp.entity.Functions;
import com.hopu.erp.entity.RoleFun;
import com.hopu.erp.service.FunctionsService;
import com.hopu.erp.service.RoleFunctionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api
@RestController
public class RoleFunctionsController {

    @Autowired
    private RoleFunctionService roleFunctionService;

    @ApiOperation("这是按角色和权限id查询角色权限关系的接口")
    @GetMapping("/role-function/{roleId}/{functionId}")
    public ResponseEntity<RoleFun> findRoleFunction(@PathVariable("roleId")String roleId,
                                                    @PathVariable("functionId")String functionId){
        RoleFun roleFunction = roleFunctionService.findRoleFunction(new RoleFun(0L,roleId,functionId));
        return ResponseEntity.ok(roleFunction);
    }

    @ApiOperation("这是查询角色权限的接口")
    @PostMapping("/role-function")
    public ResponseEntity<String> addRoleFunction(@RequestBody RoleFun roleFun){
        String str = roleFunctionService.addRoleFunction(roleFun);
        return ResponseEntity.ok(str);
    }

    @ApiOperation("这是按角色和权限id删除角色权限关系的接口")
    @DeleteMapping("/role-function/{roleId}/{functionId}")
    public ResponseEntity<String> removeRoleFunction(@PathVariable("roleId")String roleId,
                                                    @PathVariable("functionId")String functionId){
        String str = roleFunctionService.removeRoleFunction(new RoleFun(0L,roleId,functionId));
        return ResponseEntity.ok(str);
    }
}
